<template>
	<view class="materialNoMatching">
		<!-- 物资不匹配 -->
		<navBar title="物资检查" goBackUrl="/pages/inspection/materialInspection" @goBack="goBack"></navBar>
		
		<view class="content">
			<view class="title">
				检查意见: 
			</view>
			<view class="form-item form-item-description">
				<u-textarea v-model="obj.description"  placeholder="请输入内容" @blur="inputBlur"></u-textarea>
				<record class="form-item-icon form-item-icon-voice" @setText="description"></record>
				<image mode="scaleToFill" class="form-item-icon form-item-icon-clear"
				 src="/static/image/login/del1.png" @click="obj.description=''"></image>
			</view>
		</view>
		<view class="footerBtn">
			<u-button class="btn" type="primary" text="确定" @click="submit" :loading="loading"></u-button>
		</view>
	</view>
</template>

<script>
	import { getStationMaterialMatch, getProjectUserList } from "@/api/baseManage/baseManage.js"
	export default {
		data() {
			return {
				loading: false,
				obj: {
					description: ""
				},
				cursor: null,
				stationId: null,
				projectOrgs: []
			}
		},
		onLoad(options) {
			this.stationId = +options.stationId
			console.log(options);
		},
		onShow() {
			let query={
				currPage: 1,
				pageSize: 100000,
				params:{
					userId: this.$store.getters.userName.id
				}
			}
			getProjectUserList(query).then(res=>{
				let arr = []
				res.result.list.forEach(item=>{
					let obj = {
						projectId: "",    // 业主id
						projectOrgId: "", // 业主组织id
					}
					obj.projectId = item.projectId
					obj.projectOrgId = item.projectOrgId
					arr.push(obj)
				})
				this.projectOrgs = arr
			})
		},
		methods: {
			inputBlur(e){
				this.cursor=e.detail.cursor
			},
			description(text){
				let index=this.cursor||0
				let str=this.obj.description||""
				this.cursor+=text.length
				text=str.slice(0, index) + text + str.slice(index);
				this.$set(this.obj, "description", text)
				console.log(this.obj, '00000');
			},
			
			goBack(url){
				uni.navigateBack({
					url: url
				})
			},
			
			// 物资匹配
			async submit(){
				if(this.loading) return
				this.loading = true
				
				let data = {
					id: this.stationId,
					// projectOrgs: this.projectOrgs,
					isGoodsMatch: false,
					goodsReviewOpinion: this.obj.description,
				}
				let res = await getStationMaterialMatch(data)
				if(res.success){
					uni.showToast({
						title: `保存成功`,
						icon: "success"
					})
					setTimeout(()=>{
						this.loading = false
						uni.navigateBack({
							delta: 2
						});
					}, 300)
				}
				
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		padding: 0rpx 45rpx;
	}
	.title{
		font-size: 32rpx;
		margin-bottom: 15rpx;
	}
	.form-item {
		width: 100%;
		position: relative;
	}

	.form-item-description {
		.form-item-icon {
			width: 48rpx;
			height: 48rpx;
		}

		.form-item-icon-voice {
			position: absolute;
			top: 10rpx;
			right: 16rpx;
			z-index: 3;
		}
		.form-item-icon-clear{
			position: absolute;
			right: 16rpx;
			bottom: 10rpx;
			z-index: 2;
		}
	}
	.footerBtn{
		position: fixed;
		bottom: 0;
		left: 30rpx;
		right: 30rpx;
		width: 690rpx;
		height: 90rpx;
	}
</style>